<?php

namespace app\health\service;

use app\health\model\healthPro\Segment;
use think\Cache;

class MobileHomePlaceService
{
    /**
     * 获取手机号归属地
     * @param [type] $mobile
     * @Author 张旭鹏
     * @DateTime 2023-07-12
     */
    public static function inquire($mobile)
    {
        $paragraph = substr($mobile, 0, 7);
        $data = Cache::store('redis')->handler()->hget('mobile-home-place', $paragraph);
        if ($data) {
            $data = json_decode($data, true);
        } else {
            $data = Segment::where('paragraph', $paragraph)->find();
        }
        if ($data) {
            Cache::store('redis')->handler()->hset('mobile-home-place', $paragraph, json_encode($data, JSON_UNESCAPED_UNICODE));
            return [
                'province'  => $data['provice_simple'],
                'city'      => $data['city_county_simple'],
                'isp'       => $data['isp'],
                'zone_code' => $data['zone_description']
            ];
        }
        return [];
    }
}
